package xyz.scootaloo.oj.offer

import xyz.scootaloo.oj.ds.ListNode
import java.util.*

/**
 * @author flutterdash@qq.com
 * @since 2021/4/8 18:23
 */
class P06 {

    private fun reversePrint(head: ListNode?): IntArray {
        if (head == null) return intArrayOf()
        val stack = Stack<ListNode>()
        var pointer = head
        while(pointer != null) {
            stack.push(pointer)
            pointer = pointer.next
        }

        val size = stack.size
        val res = IntArray(size)
        for (idx in 0 until size) {
            res[idx] = stack.pop().`val`
        }

        return res
    }

}
